package com.example.testlaunchbroswer;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

	final static int REQUEST_CODE_MYACTIVITY = 0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Button btn = (Button)findViewById(R.id.button1);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			
				Intent i = new Intent (MainActivity.this, MyActivity.class);
				Profile p = new Profile("jyh", 19);
				i.putExtra(MyActivity.PARAM_PROFILE, p);
				startActivityForResult(i, REQUEST_CODE_MYACTIVITY);
			}
		});
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		if (requestCode == REQUEST_CODE_MYACTIVITY) {
			if (requestCode == Activity.RESULT_OK) {
				String resultName = data.getStringExtra(MyActivity.RESULT_NAME);
				int resultAge = data.getIntExtra(MyActivity.RESULT_AGE, -1);
				Toast.makeText(this, "resultName: "+ resultName + ", resultAge : "+ resultAge, Toast.LENGTH_SHORT).show();
			}
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
